package cn.itsource.config.interceptor;

import cn.itsource.config.CustomMethodArgumentResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * 声明这个springmvc的配置
 */
@Configuration
public class PetHomeMvcConfig implements WebMvcConfigurer {

//    @Autowired
//    private LoginInterceptor loginInterceptor;

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
        converters.add(new MappingJackson2HttpMessageConverter());
        resolvers.add(new CustomMethodArgumentResolver());
        //resolvers.add (new MyRequestResponseBodyMethodProcessor (converters));
        WebMvcConfigurer.super.addArgumentResolvers(resolvers);

    }

    /**
     * 注册拦截器
     *
     * @param registry
     */
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        //管理拦截器
//        registry.addInterceptor(loginInterceptor)
//                .addPathPatterns("/**") //拦截所有
//                .excludePathPatterns("/**/login", "/shop/settlement", "/file/**"
//                        , "/user/**","/wechart/**")//放行
//                .excludePathPatterns("/swagger-resources/**"
//                        , "/webjars/**"
//                        , "/v2/**"
//                        , "/swagger-ui.html/**");//放行swagger
//
//    }
}
